package com.bree.erp.jsf.view;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;

import com.bree.erp.entity.Warehouse;
import com.bree.erp.jsf.datatable.LazyBreeDataModel;
import com.bree.erp.service.WarehouseService;

@ManagedBean(name = "dtWarehouseLazyView")
@ViewScoped
public class WarehouseLazyView {
	
	@EJB
	private WarehouseService warehouseService;

	private LazyDataModel<Warehouse> lazyModel;
	
	private Warehouse selectedItem;

	@PostConstruct
	public void init() {
		lazyModel = new LazyBreeDataModel<Warehouse, WarehouseService, String>(
				warehouseService, "");
	}

	public void onRowSelect(SelectEvent event) {
		FacesMessage msg = new FacesMessage("Item Selected",
				((Warehouse) event.getObject()).getId() + "");
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

	/**
	 * @return the lazyModel
	 */
	public LazyDataModel<Warehouse> getLazyModel() {
		return lazyModel;
	}

	/**
	 * @param lazyModel the lazyModel to set
	 */
	public void setLazyModel(LazyDataModel<Warehouse> lazyModel) {
		this.lazyModel = lazyModel;
	}

	/**
	 * @return the selectedItem
	 */
	public Warehouse getSelectedItem() {
		return selectedItem;
	}

	/**
	 * @param selectedItem the selectedItem to set
	 */
	public void setSelectedItem(Warehouse selectedItem) {
		this.selectedItem = selectedItem;
	}
}
